//
//  HMMainViewController.swift
//  weibo
//
//  Created by LCH on 16/3/2.
//  Copyright © 2016年 lch. All rights reserved.
//

import UIKit

class HMMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tb = HMTabBar()
// 这句话的作用 ???  kvc赋值
        
        tb.composeButtonClickClouse = { [weak self] in
            
            print("哈哈我要弹出控制器\(self)")
        }

        
        self.setValue(tb, forKeyPath: "tabBar")
    
        // 添加子控制器
        addChildViewController(HMHomeTableTableViewController(), imageNamed: "tabbar_home", title: "首页")
        addChildViewController(HMMessageTableViewController(), imageNamed: "tabbar_message_center", title: "消息")
        addChildViewController(HMDiscoverTableViewController(), imageNamed: "tabbar_discover", title: "发现")
        addChildViewController(HMProfileTableViewController(), imageNamed: "tabbar_profile", title: "我")
        
        
         
        
        
      
    }
    private func addChildViewController(childController: UIViewController , imageNamed: String, title: String) {
    
    
      childController.title = title
        
      childController.tabBarItem.image = UIImage(named: imageNamed)?.imageWithRenderingMode(.AlwaysOriginal)
        
      childController.tabBarItem.selectedImage = UIImage(named: "\(imageNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let attr = [NSForegroundColorAttributeName:UIColor.orangeColor()]
        
        childController.tabBarItem.setTitleTextAttributes(attr, forState:UIControlState.Selected)
        
        addChildViewController(HMNavigationController(rootViewController: childController))
        
     
    }
    

}
